<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>YDCMS Admin Login</title>
    <link rel="stylesheet" href="/static/css/bootstrap.min.css">
    <style>
        body {
            background: url('/static/images/bg-trade.jpg') no-repeat center center fixed;
            background-size: cover;
            min-height: 100vh;
        }
        .login-container {
            max-width: 420px;
            margin: 100px auto;
            background: rgba(255,255,255,0.95);
            border-radius: 12px;
            box-shadow: 0 4px 32px rgba(0,0,0,0.15);
            padding: 40px 30px 30px 30px;
        }
        .login-logo {
            text-align: center;
            margin-bottom: 30px;
        }
        .login-logo h1 {
            color: #1a237e;
            font-size: 28px;
            font-weight: bold;
        }
        .login-logo span {
            color: #1976d2;
            font-size: 16px;
            letter-spacing: 2px;
        }
        .login-card .form-control {
            height: 45px;
            margin-bottom: 20px;
        }
        .login-card .btn {
            height: 45px;
            font-size: 16px;
        }
        .captcha-title {
            font-size: 15px;
            color: #333;
            margin-bottom: 10px;
            font-weight: 500;
        }
        .captcha-grid {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 8px;
            margin-bottom: 18px;
        }
        .captcha-img {
            width: 100%;
            height: 70px;
            object-fit: cover;
            border-radius: 6px;
            border: 2px solid #eee;
            cursor: pointer;
            transition: border 0.2s;
        }
        .captcha-img.selected {
            border: 2px solid #1976d2;
            box-shadow: 0 0 8px #1976d2;
        }
        .captcha-tip {
            font-size: 13px;
            color: #888;
            margin-bottom: 10px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="login-container">
            <div class="login-logo">
                <h1>YDCMS 管理系统</h1>
                <span>International Trade CMS</span>
            </div>
            <div class="login-card">
                <?php if (isset($error)): ?>
                    <div class="alert alert-danger"><?php echo $error; ?></div>
                <?php endif; ?>
                <form action="/admin/login" method="post" id="loginForm">
                    <div class="mb-3">
                        <input type="text" class="form-control" name="username" placeholder="用户名 / Username" required>
                    </div>
                    <div class="mb-3">
                        <input type="password" class="form-control" name="password" placeholder="密码 / Password" required>
                    </div>
                    <div class="captcha-title">请选择所有包含 <b>货轮</b> 的图片</div>
                    <div class="captcha-tip">Select all images with <b>cargo ships</b></div>
                    <div class="captcha-grid" id="captchaGrid">
                        <img src="/static/captcha/1.jpg" class="captcha-img" data-type="ship">
                        <img src="/static/captcha/2.jpg" class="captcha-img" data-type="sea">
                        <img src="/static/captcha/3.jpg" class="captcha-img" data-type="ship">
                        <img src="/static/captcha/4.jpg" class="captcha-img" data-type="container">
                        <img src="/static/captcha/5.jpg" class="captcha-img" data-type="ship">
                        <img src="/static/captcha/6.jpg" class="captcha-img" data-type="crane">
                        <img src="/static/captcha/7.jpg" class="captcha-img" data-type="container">
                        <img src="/static/captcha/8.jpg" class="captcha-img" data-type="sea">
                        <img src="/static/captcha/9.jpg" class="captcha-img" data-type="crane">
                    </div>
                    <input type="hidden" name="captcha_selection" id="captchaSelection">
                    <button type="submit" class="btn btn-primary w-100">登录 / Login</button>
                </form>
            </div>
        </div>
    </div>
    <script src="/static/js/bootstrap.bundle.min.js"></script>
    <script>
        // 图片选择验证码交互
        const imgs = document.querySelectorAll('.captcha-img');
        const selectionInput = document.getElementById('captchaSelection');
        imgs.forEach((img, idx) => {
            img.addEventListener('click', function() {
                img.classList.toggle('selected');
                // 记录所有被选中的图片索引
                const selected = [];
                imgs.forEach((im, i) => {
                    if (im.classList.contains('selected')) selected.push(i);
                });
                selectionInput.value = selected.join(',');
            });
        });
        // 提交前校验必须选中至少一张
        document.getElementById('loginForm').addEventListener('submit', function(e) {
            if (!selectionInput.value) {
                alert('请先选择所有包含货轮的图片！');
                e.preventDefault();
            }
        });
    </script>
</body>
</html> 